export default {
    isUndef(text) {
        return text === undefined || text === null;
    },
    isDef(text) {
        return text !== undefined && text !== null;
    },
    isEmptyObject(obj) {
        for (let i in obj) {
            return false;
        }
        return true;
    },
    padLeftZero(str) {
        if (String(str).length < 2) {
            return '0' + str;
        }
        return str;
    },
    formatDate(date, fmt) {
        if (typeof date === 'number') {
            date = new Date(date);
        } else {
            date = new Date();
        }
        let o = {
            'Y': date.getFullYear(),
            'M': date.getMonth() + 1,
            'D': date.getDate(),
            'h': date.getHours(),
            'm': date.getMinutes(),
            's': date.getSeconds()
        };
        for (let k in o) {
            if (new RegExp(`(${k})`).test(fmt)) {
                let str = o[k] + '';
                fmt = fmt.replace(RegExp.$1, this.padLeftZero(str));
            }
        }
        return fmt
    },
    getDate(time, fmt) {
        if (typeof time === 'string') {
            fmt = time;
            time = Date.now();
        }
        return this.formatDate(time, fmt);
    },
    getStartDateTime(time) {
        const oDate = new Date(time || Date.now());
        oDate.setHours(0);
        oDate.setSeconds(0);
        oDate.setMinutes(0);
        return oDate.getTime();
    },
    getCurrentEedDateTime(time) {
        const oDate = new Date(time || Date.now());
        oDate.setHours(23);
        oDate.setSeconds(59);
        oDate.setMinutes(59);
        return oDate.getTime();
    },
    extend() {
        const arg = arguments;
        let type;
        let obj1 = arguments[0], obj2 = arguments[1];
        if (typeof obj2 == 'object') {
            for (let i in obj2) {
                obj1[i] = this.extend(obj1[i], obj2[i])
            }
        } else if (!obj2) {
            obj1 = obj2;
        }
        return obj1;
    }
}